<template>
  <view class="custom-tabbar">
    <!-- 左侧 TabBar 项 -->
    <view class="tabbar-item" v-for="(item, index) in tabList" :key="index" @click="switchTab(index)">
      <image :src="item.icon" class="tabbar-icon" :class="{ 'active': currentIndex === index }"></image>
      <text class="tabbar-text" :class="{ 'active': currentIndex === index }">{{ item.text }}</text>
    </view>

    <!-- 中间凸起按钮 -->
    <view class="tabbar-center-container">
      <view class="tabbar-center-border">
        <view class="tabbar-center" @click="switchTab(2)">
          <image src="/static/center-icon.png" class="center-icon"></image>
        </view>
      </view>
    </view>
  </view>
</template>

<script>
export default {
  data() {
    return {
      currentIndex: 0,
      tabList: [
        { icon: '/static/home.png', text: '首页' },
        { icon: '/static/category.png', text: '分类' },
        { icon: '', text: '' }, // 中间按钮占位
        { icon: '/static/cart.png', text: '购物车' },
        { icon: '/static/profile.png', text: '我的' }
      ]
    };
  },
  methods: {
    switchTab(index) {
      this.currentIndex = index;
      // 这里可以添加页面跳转逻辑
      if (index === 2) {
        uni.navigateTo({
          url: '/pages/center/center'
        });
      } else {
        uni.switchTab({
          url: this.tabList[index].url
        });
      }
    }
  }
};
</script>

<style scoped>
.custom-tabbar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: 100px;
  background-color: #ffffff;
  display: flex;
  justify-content: space-around;
  align-items: center;
  box-shadow: 0px -2px 10px rgba(0, 0, 0, 0.1);
}

.tabbar-item {
  display: flex;
  flex-direction: column;
  align-items: center;
}

.tabbar-icon {
  width: 40px;
  height: 40px;
}

.tabbar-text {
  font-size: 24px;
  color: #666666;
}

.tabbar-text.active {
  color: #007AFF;
}

/* 中间按钮容器 */
.tabbar-center-container {
  position: absolute;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 100px;
  height: 100px;
  display: flex;
  justify-content: center;
  align-items: center;
}

/* 白色边框 */
.tabbar-center-border {
  width: 100px;
  height: 100px;
  background-color: white;
  border-radius: 50%;
  display: flex;
  justify-content: center;
  align-items: center;
  box-shadow: 0px 4px 10px rgba(0, 0, 0, 0.1);
}

/* 中间按钮 */
.tabbar-center {
  width: 70px;
  height: 70px;
  background-color: #007AFF;
  border-radius: 50%;
  display: flex;
  justify-content: center;
  align-items: center;
  box-shadow: 0px 4px 10px rgba(0, 122, 255, 0.5);
}

.center-icon {
  width: 40px;
  height: 40px;
}
</style>